home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / extra / pro13 / atoi.c < prev    next >
C/C++ Source or Header  |  1993-02-01  |  498b  |  38 lines

  1. /*
  2.     atoi.C
  3.  
  4.     Copyright (C) 1993, Geoff Friesen B.Sc.
  5.     All rights reserved.
  6. */
  7.  
  8. #define    INCL_ATOI
  9.  
  10. #ifndef INCL_ISDIGIT
  11. #include "isdigit.C"
  12. #endif
  13.  
  14. #ifndef INCL_ISSPACE
  15. #include "isspace.C"
  16. #endif
  17.  
  18. int atoi (const char *s)
  19. {
  20.    int num, sign = 1;
  21.  
  22.    while (isspace (*s))
  23.       s++;
  24.  
  25.    if (*s == '+')
  26.        s++;
  27.    else
  28.    if (*s == '-')
  29.    {
  30.        s++;
  31.        sign = -1;
  32.    }
  33.  
  34.    for (num = 0; isdigit (*s); s++)
  35.     num = 10*num+*s-'0';
  36.  
  37.    return sign*num;
  38. }